package kz.kstu.scantest.facade.ejb.impl;

import kz.kstu.scantest.business.common.form.FormType;
import kz.kstu.scantest.business.entity.data.FormData;
import kz.kstu.scantest.business.entity.guide.School;
import kz.kstu.scantest.business.server.api.FormDataService;
import kz.kstu.scantest.facade.ejb.api.FormDataFacade;

import javax.ejb.Stateless;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.List;

/**
 * @author Filipp_Stankevich
 *         created: 14.09.11 22:29
 */
@Stateless
public class FormDataFacadeBean extends AbstractFacadeBean implements FormDataFacade {
    @Override
    public List<FormData> checkFormData(List<FormData> formDataList) {
        return getService(FormDataService.class).checkFormData(formDataList);
    }

    @Override
    public FormData processFormData(byte[] data, School school, FormType formType) throws UnsupportedEncodingException {
        FormData formData = getService(FormDataService.class).parse(data, formType);
        formData.setSchool(school);
        validateAndSaveFormData(formData);
        return formData;
    }

    @Override
    public FormData validateAndSaveFormData(FormData formData) {
        return getService(FormDataService.class).validateAndSaveFormData(formData);
    }

    @Override
    public List<FormData> findByDateAndSchool(Date date, School school) {
        return getService(FormDataService.class).findByDateAndSchool(date, school);
    }

    @Override
    public List<FormData> findByDateAndSchoolWithErrors(Date date, School school) {
        return getService(FormDataService.class).findByDateAndSchoolWithErrors(date, school);
    }

    @Override
    public void saveFormData(FormData formData) {
        getService(FormDataService.class).saveFormData(formData);
    }

    @Override
    public void removeFormData(Long id) {
        getService(FormDataService.class).removeFormData(id);
    }

    @Override
    public List<Date> findScanDatesBySchool(School school) {
        return getService(FormDataService.class).findScanDatesBySchool(school);
    }

    @Override
    public FormData findFormDataById(Long id) {
        return getService(FormDataService.class).findFormDataById(id);
    }
}
